package com.xiaomazi.edu.controller.front;

import com.xiaomazi.common.utils.JwtUtils;
import com.xiaomazi.common.utils.R;
import com.xiaomazi.edu.dto.front.CommentFrontDTO;
import com.xiaomazi.edu.entity.Comment;
import com.xiaomazi.edu.service.CommentService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: llxy-parent
 * @description: 评论前端控制器
 * @author: 小马子
 * @create: 2023-03-04 10:43
 **/
@Api(tags = "评论管理")
@RestController
@RequestMapping("/eduservice/comment")
public class CommentFrontController {

    @Autowired
    private CommentService commentService;

    @PostMapping("/getCommentsByCourseId")
    public R getCommentsByCourseId(@RequestBody CommentFrontDTO commentFrontDTO){
        return commentService.getCommentsByCourseId(commentFrontDTO);
    }

    @PostMapping("/saveComment")
    public R saveComment(@RequestBody Comment comment,HttpServletRequest request){
        return commentService.saveComment(comment,JwtUtils.getMemberIdByJwtToken(request));
    }

}
